//
//  FXTHttpResponseModel.m
//  OfferJob
//
//  Created by 郑州动力无限科技 on 2017/6/30.
//  Copyright © 2017年 郑州动力无限科技. All rights reserved.
//

#import "FXTHttpResponseModel.h"

@implementation FXTHttpResponseModel
@synthesize error = _error;
@synthesize code = _code;
@synthesize data = _data;

-(id)initWithData:(id)responseData err:(NSError *)err {
    if (self =[super init]) {
        if (err) {
            _state =FXTReponseCodeState_Faild;
            if ([responseData isKindOfClass:[NSDictionary class]]) {
                NSNumber *code = [responseData objectForKey:@"code"];
                NSString *errorMsg =[responseData objectForKey:@"result"];
                _error = [NSError errorWithDomain:errorMsg
                                             code:code.integerValue
                                         userInfo:nil];
            }
        }else {
            if ([responseData isKindOfClass:[NSDictionary class]]) {// 正常返回数据处理
                NSNumber *codeNum =responseData[@"code"];
                id data = [responseData valueForKey:@"body"];
                if ([codeNum intValue] ==200) {
                    _state =FXTReponseCodeState_Success;
                    _data =data;
                }else if ([codeNum intValue] ==204) {
                    _state =FXTReponseCodeState_NoParams;
                    _data =data;
                }
                NSString *alertMsg =[responseData objectForKey:@"result"];
                _alertMsg =alertMsg;
                _code =[codeNum integerValue];
            }else {
                _state =FXTReponseCodeState_Faild;
                
                _error = [NSError errorWithDomain:@"服务器返回数据结构异常"
                                             code:-100
                                         userInfo:nil];
            }
        }
    }
    return self;
}

@end
